// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import i18n from './lang';
import VueClipboard from 'vue-clipboard2'
import {isLogin, isLoginBefore} from './service/loginService'
import ecc from 'eosjs-ecc'
import moment from 'moment'
import QRCode from 'qrcodejs2'


Vue.prototype.QRCode=QRCode
moment.locale('en-NZ')

ecc.initialize();

Vue.use(VueClipboard)

// require('./mock');

Vue.config.productionTip = false;

router.beforeEach((to, from, next) => {
  if (!to.meta.fluid) {
    if (isLogin()) {
      next();
    } else {
      if (isLoginBefore()) {
        next({path: '/login'})
      } else {
        next({path: '/register'})
      }
      next();
    }
  } else {
    if (to.path === '/login' && !isLoginBefore()) {
      next({path: '/register'})
    }
    next();
  }
});


Vue.use(ElementUI, {
  size: 'medium', // set element-ui default size
  i18n: (key, value) => i18n.t(key, value)
});


/* eslint-disable no-new */
new Vue({
  i18n,
  el: '#app',
  router,
  components: {App},
  template: '<App/>'
});
